package com.smashcrush.server.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.smashcrush.server.service.UserService;


@Controller
@Path("/api/user")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UserResource {

	@Autowired
	UserService userService;

	@POST
	@Path("loginf")
	public String login() {
		return "asdf";
	}
	
	@POST
	@Path("login/{emailAddress}/{password}")
	public String login(@PathParam("emailAddress") String emailAddress,
			@PathParam("password") String password) throws Exception {
		
		String token = userService.login(emailAddress, password);
		if (token != null) {
			token = "\"" + token + "\"";
		}
		
		return token;
	}

	@POST
	@Path("register/{emailAddress}/{password}")
	public String register(@PathParam("emailAddress") String emailAddress,
			@PathParam("password") String password) {
		return userService.register(emailAddress, password);
	}

}